home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / useTextureAlphasForTranspare < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.0 KB  |  94 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Description:
  18. // Go through all shaders in the scene, find the file texture nodes directly connected 
  19. // to the color attribute. For each file texture connected to the color attribute, we 
  20. // connect the outTransparency too if and only if:
  21. //
  22. //    - There isn't anything connected to the shader's transparency attribute.
  23. //    - The file texture contains some transparent pixels (ie: fileTexture.fileHasAlpha == 1)
  24. //
  25. global proc useTextureAlphasForTransparency()
  26. {
  27.     string $materials[];
  28.  
  29.     // Get a list of all material nodes in the scene
  30.     //
  31.     $materials = `ls -materials`;
  32.  
  33.     int $i;
  34.  
  35.     for ($i = 0; $i < size($materials); $i++)
  36.     {
  37.         if (    (size(`ls ($materials[$i] + ".color")`) != 0)
  38.             &&    (size(`ls ($materials[$i] + ".transparency")`) != 0))
  39.         {
  40.             //
  41.             // The material has color and transparency attributes
  42.             //
  43.  
  44.             // Determine the source node of the color attribute of the material
  45.             // (if any)
  46.             //
  47.             string $colorSrc[];
  48.  
  49.             $colorSrc = 
  50.                 `listConnections 
  51.                     -source true 
  52.                     -destination false
  53.                     ($materials[$i] + ".color")`;
  54.             
  55.             // Determine the source node of the transparency attribute of the
  56.             // material (if any)
  57.             //
  58.             string $transparencySrc[];
  59.  
  60.             $transparencySrc = 
  61.                 `listConnections 
  62.                     -source true 
  63.                     -destination false
  64.                     ($materials[$i] + ".transparency")`;
  65.             
  66.             string $colorTextureName = $colorSrc[0]; 
  67.             int $fileHasAlpha = ($colorTextureName != "") 
  68.                     && (`nodeType $colorTextureName` == "file") 
  69.                     && (`getAttr ($colorTextureName+".fileHasAlpha")`);
  70.  
  71.  
  72.             if ($fileHasAlpha && ($colorSrc[0] != "") && ($transparencySrc[0] == ""))
  73.             {
  74.                 //
  75.                 // The color attribute has a source node, and the transparency
  76.                 // attribute doesn't
  77.                 //
  78.  
  79.                 if (size(`ls ($colorSrc[0] + ".outTransparency")`) != 0)
  80.                 {
  81.                     // The source node of the color attribute of the material
  82.                     // also has an outTransparency attribute, so we will
  83.                     // connect it to the transparency attribute of the
  84.                     // material.
  85.                     // 
  86.                     connectAttr 
  87.                         ($colorSrc[0] + ".outTransparency")
  88.                         ($materials[$i] + ".transparency");
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
  94.